<?php
/**
 *
 * (model)
 */
namespace App\Models\SalesReport;

use App\Models\Basics\SysCountry;
use App\Models\Basics\SysArea;
use Illuminate\Database\Eloquent\Model;
class PaymentTCDetail extends Model
{
    protected $table = 'sr_payment_country';

    protected $guarded = [];

    public $timestamps = false;

    public function area(){
        return $this->belongsTo(SysArea::class,'area_id');
    }

    public function country(){
        return $this->belongsTo(SysCountry::class,'country_id');
    }

    public static $_basic = [
        'report_date' => ['title' => '日期','sumField' => false,'per' => false],
        'area' => ['title' => '站点','sumField' => false,'per' => false],
        'country' => ['title' => '国家','sumField' => false,'per' => false],
    ];

    public static function getDataBasic($row): array
    {
        return [
            $row->report_date,
            $row->area->area ?? '',
            $row->country->country ?? '',
        ];
    }

    public static function headersField(): array
    {
        return self::$_basic + PaymentTNSummary::$_common;
    }

    public static function getDownloadData($re): \Generator
    {
        foreach ($re as $row){
            yield self::getDataBasic($row) + PaymentTNSummary::getNumDataCommon($row);
            yield self::getDataBasic($row) + PaymentTNSummary::getPerDataCommon($row);
        }
    }

    public static function getDownloadNumData($re): \Generator
    {
        foreach ($re as $row){
            yield self::getDataBasic($row) + PaymentTNSummary::getNumDataCommon($row);
        }
    }

    public static function getDownloadPerData($re): \Generator
    {
        foreach ($re as $row){
            yield self::getDataBasic($row) + PaymentTNSummary::getPerDataCommon($row);
        }
    }
}
